rm(list = ls())

library(sf)
library(tidyverse)
library(maps)
library(usmap)
library(ggplot2)

#########################################

# set file paths (pull from Stata file 00_main.do)
raw_path          <- Sys.getenv("RAW")
intermediate_path <- Sys.getenv("INTERMEDIATE")
for_analysis_path <- Sys.getenv("FOR_ANALYSIS")
temp_path         <- Sys.getenv("TEMP")
output_path       <- Sys.getenv("OUTPUT")

# read in dataset with CAP formats
snap_policy <- read.csv(file.path(intermediate_path, "state_cap_sm_year.csv"), header = T, stringsAsFactors = F)
snap_policy$Format <- as.factor(snap_policy$format)

#########################################

# generate map
policy_map <- plot_usmap(data = snap_policy, values = "Format", color = "white") + 
  theme(legend.position = "right")+
  scale_fill_manual(values = c('deepskyblue', 'bisque2'))

ggplot2::ggsave(filename = file.path(output_path, "policy_map.png"), plot = policy_map, device = "png", dpi = 1200)
